<?php

namespace App\Jobs;

use App\Libs\Sms\Sms;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log;

class SendSms implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    public $mobile;

    public $templateId;

    public $params;

    /**
     * Create a new job instance.
     */
    public function __construct($mobile, $templateId, $params)
    {
        $this->mobile = $mobile;
        $this->templateId = $templateId;
        $this->params = $params;
        Log::info('发送短信创建: ' . var_export($mobile, true) . ' ' . $templateId);
    }

    /**
     * Execute the job.
     */
    public function handle(): void
    {
        Sms::sendSms($this->mobile, $this->templateId, $this->params);
        Log::info('发送短信完成: ' . var_export($this->mobile, true) . ' ' . $this->templateId);
    }
}
